import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/modulePage/model/module_data.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';

import 'module_grid_item.dart';

class ModuleGrid extends StatelessWidget {
  final ModuleData data;
  final double iconSize;
  final ValueChanged<Module> onItemTap;

  const ModuleGrid(
    this.data, {
    this.onItemTap,
    this.iconSize,
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(top: 30.w),
          child: Text(data.title, style: TextStyleConstant().normal_1_36.copyWith(fontWeight: FontWeight.w500)),
        ),
        GridView.builder(
          padding: EdgeInsets.zero,
          physics: const NeverScrollableScrollPhysics(),
          shrinkWrap: true,
          itemCount: data.data.length,
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
          itemBuilder: (context, index) {
            var current = data.data[index];

            return ModuleGridItem(
              current,
              iconSize: iconSize,
              onTap: () async {
                if (onItemTap != null) onItemTap(current);
              },
            );
          },
        )
      ],
    );
  }
}
